package com.dehui.traders.service;

import com.dehui.traders.bean.Announcement;
import com.dehui.traders.bean.BaseListResponse;
import com.dehui.traders.bean.BaseResponse;
import com.dehui.traders.bean.FinancialData;
import com.dehui.traders.bean.HistData;
import com.dehui.traders.bean.IndexInfo;
import com.dehui.traders.bean.MsgBean;
import com.dehui.traders.bean.OptionalCode;
import com.dehui.traders.bean.OptionalCodeRank;
import com.dehui.traders.bean.PlateListBean;
import com.dehui.traders.bean.PredictBean;
import com.dehui.traders.bean.RealtimeQuote;
import com.dehui.traders.bean.SearchCodeResult;
import com.dehui.traders.service.request.PredictRequest;
import com.dehui.traders.service.request.PullRequest;
import com.dehui.traders.service.request.TradeupdownListRequest;
import com.dehui.traders.ui.stockdetail.bean.LabelTabel;
import com.dehui.traders.ui.stockdetail.bean.StockCapital;
import com.dehui.traders.bean.StockMinuteResponse;
import com.dehui.traders.bean.StrategyInfo;
import com.dehui.traders.bean.TrendInfo;
import com.dehui.traders.bean.UserDetail;
import com.dehui.traders.bean.UserInfo;
import com.dehui.traders.service.request.CodeRequest;
import com.dehui.traders.service.request.DeleteOptionRequest;
import com.dehui.traders.service.request.GetByPhoneRequest;
import com.dehui.traders.service.request.GetRealTimeQuotesRequest;
import com.dehui.traders.service.request.HistDataRequest;
import com.dehui.traders.service.request.LoginRequest;
import com.dehui.traders.service.request.NulRequest;
import com.dehui.traders.service.request.RealtimeQuotesRequest;
import com.dehui.traders.service.request.RegisterRequest;
import com.dehui.traders.service.request.SCodeRequest;
import com.dehui.traders.service.request.SaveCodeRequest;
import com.dehui.traders.service.request.SearchCodeNameRequest;
import com.dehui.traders.service.request.SendCodeRequest;
import com.dehui.traders.service.request.WxLoginRequest;
import com.dehui.traders.utils.JsonConvertor;

import java.util.List;
import java.util.Map;

import okhttp3.RequestBody;
import retrofit2.Call;

/**
 * Created by hqq on 18.5.7.
 */

public class NetImpl {

    /**
     * 获取验证码
     * @param phone
     * @return
     */
    public static Call<BaseResponse<Object>> sendCode(String phone){
        RequestBody requestBody = JsonConvertor.getRequestBody(new SendCodeRequest(phone));
        return RetrofitHelper.getAPI().sendCode(requestBody);
    }

    /**
     * 注册
     * @param loginName
     * @param password
     * @param code
     * @return
     */
    public static Call<BaseResponse<String>> register(String loginName,String password,String code){
        RequestBody requestBody = JsonConvertor.getRequestBody(new RegisterRequest(loginName,password,code));
        return RetrofitHelper.getAPI().register(requestBody);
    }

    /**
     * 登陆
     * @param loginName
     * @param password
     * @return
     */
    public static Call<BaseResponse<Object>> login(String loginName, String password,String registerId){
        RequestBody requestBody = JsonConvertor.getRequestBody(new LoginRequest(loginName,password,registerId));
        return RetrofitHelper.getAPI().login(requestBody);
    }

    /**
     * 微信登录
     * @param token
     * @param openId
     * @param headimgurl
     * @param nickname
     * @return
     */
    public static Call<BaseListResponse<UserInfo>> wxLogin(String token,String openId,String headimgurl,String nickname,String register_id){
        RequestBody requestBody = JsonConvertor.getRequestBody(
                new WxLoginRequest(token,openId,headimgurl,nickname,register_id));
        return RetrofitHelper.getAPI().wechatLogin(requestBody);
    }

    /**
     * 大盘指数行情列表
     * @return
     */
    public static Call<BaseListResponse<IndexInfo>> realtimeQuotes(String id){
        RequestBody requestBody = JsonConvertor.getRequestBody(new RealtimeQuotesRequest(id));
        return RetrofitHelper.getAPI().realTimeQuotes(requestBody);
    }

    /**
     * 是否已收盘
     * @return
     */
    public static Call<BaseResponse<Integer>> getTime(){
        return RetrofitHelper.getAPI().getTime(RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"), "{}"));
    }

    /**
     * 分时图
     * @param code
     * @return
     */
    public static Call<StockMinuteResponse> getTodayTicks1(String code){
        RequestBody requestBody = JsonConvertor.getRequestBody(new CodeRequest(code));
        return RetrofitHelper.getAPI().getTodayTicks1(requestBody);
    }

    /**
     * 自选股查询
     * @param userId
     * @return
     */
    public static Call<BaseListResponse<OptionalCode>> getOptionalByPhone(String userId){
        RequestBody requestBody = JsonConvertor.getRequestBody(new GetByPhoneRequest(userId));
        return RetrofitHelper.getAPI().getByPhone(requestBody);
    }


    /**
     * 根据关键词搜索自选股
     * @param key
     * @return
     */
    public static Call<BaseListResponse<SearchCodeResult>> searchCodeAndName(String key){
        RequestBody requestBody = JsonConvertor.getRequestBody(new SearchCodeNameRequest(key));
        return RetrofitHelper.getAPI().searchCodeAndName(requestBody);
    }


    /**
     * 自选股添加
     * @param code
     * @param market
     * @param userId
     * @param status
     * @param name
     * @param type
     * @return
     */
    public static Call<BaseResponse<String>> saveCode(String code,
                                                      String market,String userId,String status,String name,String type){
        RequestBody requestBody = JsonConvertor.getRequestBody(new SaveCodeRequest(code,market,userId,status,name,type));
        return RetrofitHelper.getAPI().saveCode(requestBody);
    }

    /**
     * 实时分笔接口
     * @param list
     * @return
     */
    public static Call<BaseListResponse<RealtimeQuote>> getRealtimeQuote(List<OptionalCodeRank> list){
        RequestBody requestBody = JsonConvertor.getRequestBody(new GetRealTimeQuotesRequest(list));
        return RetrofitHelper.getAPI().getRealtimeQuotes(requestBody);
    }

    /**
     * 自选股删除
     * @param code
     * @param market
     * @return
     */
    public static Call<BaseResponse<String>> deleteCode(String code, String market){
        RequestBody requestBody = JsonConvertor.getRequestBody(new DeleteOptionRequest(code,market));
        return RetrofitHelper.getAPI().deleteOption(requestBody);
    }

    /**
     * 获取股票历史买卖点信息
     * @param code
     * @return
     */
    public static Call<BaseListResponse<String[]>> getKBussinessLabelPoint(String code){
        RequestBody requestBody = JsonConvertor.getRequestBody(new CodeRequest(code));
        return RetrofitHelper.getAPI().getKBussinessLabelPoint(requestBody);
    }

    /**
     * 获取单个股票今日买卖点
     * @param code
     * @return
     */
    public static Call<BaseListResponse<String[]>> getTodayBussinessLabelPoint(String code){
        RequestBody requestBody = JsonConvertor.getRequestBody(new CodeRequest(code));
        return RetrofitHelper.getAPI().getTodayBussinessLabelPoint(requestBody);
    }

    /**
     * 获取个股历史交易信息数据
     * @param code
     * @param status
     * @return
     */
    public static Call<BaseListResponse<HistData>> getHistData(String code, String status){
        RequestBody requestBody = JsonConvertor.getRequestBody(new HistDataRequest(code,status));
        return RetrofitHelper.getAPI().getHistData(requestBody);
    }

    /**
     * 大势
     * @return
     */
    public static Call<BaseResponse<TrendInfo>> queryTrend(){
        RequestBody requestBody = JsonConvertor.getRequestBody(new NullPointerException());
        return RetrofitHelper.getAPI().queryTrend(requestBody);
    }

    /**
     * 策略查询
     * @param userId
     * @return
     */
    public static Call<BaseListResponse<StrategyInfo>> queryStrategy(String userId){
        RequestBody requestBody = JsonConvertor.getRequestBody(new GetByPhoneRequest(userId));
        return RetrofitHelper.getAPI().queryStrategy(requestBody);
    }

    /**
     * 获取个股周线图数据
     * @param code
     * @return
     */
    public static Call<BaseListResponse<String[]>> getBussinessLabellwPoint(String code){
        RequestBody requestBody = JsonConvertor.getRequestBody(new CodeRequest(code));
        return RetrofitHelper.getAPI().getBussinessLabellwPoint(requestBody);
    }

    /**
     * 个人信息修改
     * @param userId
     * @param map
     * @return
     */
    public static Call<BaseResponse<Object>> saveUser(String userId,Map<String,String> map){
        map.put("userId",userId);
        RequestBody requestBody = JsonConvertor.getRequestBody(map);
        return RetrofitHelper.getAPI().saveUser(requestBody);
    }

    /**
     * 个人信息查看
     * @param userId
     * @return
     */
    public static Call<BaseResponse<UserDetail>> queryUser(String userId){
        RequestBody requestBody = JsonConvertor.getRequestBody(new GetByPhoneRequest(userId));
        return RetrofitHelper.getAPI().queryUser(requestBody);
    }

    /**
     * 公告基本信息
     * @param code
     * @return
     */
    public static Call<BaseListResponse<Announcement>> queryAnnouncement(String code){
        RequestBody requestBody = JsonConvertor.getRequestBody(new SCodeRequest(code));
        return RetrofitHelper.getAPI().queryAnnouncement(requestBody);
    }

    /**
     * 财务数据
     * @param code
     * @return
     */
    public static Call<BaseListResponse<FinancialData[]>> queryFinancialData(String code){
        RequestBody requestBody = JsonConvertor.getRequestBody(new SCodeRequest(code));
        return RetrofitHelper.getAPI().queryFinancialData(requestBody);
    }

    /**
     * 资金流向板块
     * @return
     */
    public static Call<BaseListResponse<StockCapital>> stockCapital(){
        RequestBody requestBody = JsonConvertor.getRequestBody(new NulRequest());
        return RetrofitHelper.getAPI().stockCapital(requestBody);
    }

    /**
     * 获取个股买卖点
     * @param code
     * @return
     */
    public static Call<BaseListResponse<LabelTabel>> getLabelTabel(String code){
        RequestBody requestBody = JsonConvertor.getRequestBody(new CodeRequest(code));
        return RetrofitHelper.getAPI().getLabelTabel(requestBody);
    }

    /**
     * 获取预测买卖点
     * @param code
     * @return
     */
    public static Call<BaseListResponse<PredictBean>> getNextLalTabel(String code, String userId){
        RequestBody requestBody = JsonConvertor.getRequestBody(new PredictRequest(code,userId));
        return RetrofitHelper.getAPI().getNexlLabelTable(requestBody);
    }

    /**
     * 股东
     * @param code
     * @return
     */
    public static Call<BaseListResponse<FinancialData[]>> querySahreHolderData(String code){
        RequestBody requestBody = JsonConvertor.getRequestBody(new SCodeRequest(code));
        return RetrofitHelper.getAPI().queryShareHolderData(requestBody);
    }

    /**
     * 板块列表
     * @return
     */
    public static Call<BaseListResponse<PlateListBean>> updownlist(String code, int page){
        RequestBody requestBody = JsonConvertor.getRequestBody(new TradeupdownListRequest(code,page,10));
        return RetrofitHelper.getAPI().updownlist(requestBody);
    }

    /**
     * 板块列表
     * @return
     */
    public static Call<BaseListResponse<PlateListBean.PlateData>> updownlistRank(String code, int page){
        RequestBody requestBody = JsonConvertor.getRequestBody(new TradeupdownListRequest(code,page,20));
        return RetrofitHelper.getAPI().updownlistRank(requestBody);
    }

    /**
     * 板块列表
     * @return
     */
    public static Call<BaseListResponse<PlateListBean.PlateData>> tradeupdownlist(String code, int page){
        RequestBody requestBody = JsonConvertor.getRequestBody(new TradeupdownListRequest(code,page,10));
        return RetrofitHelper.getAPI().tradeupdownlist(requestBody);
    }

    /**
     * 消息列表
     * @param userid
     * @return
     */
    public static Call<BaseResponse<List<MsgBean>>> pushMessage(String userid){
        RequestBody requestBody = JsonConvertor.getRequestBody(new PullRequest(userid));
        return RetrofitHelper.getAPI().pushMessage(requestBody);
    }

}
